export const getToken = (): string => {
  return '';
};

export const getIESLocation = () => {
  return new Promise((resolve, reject) => {
    let timeout = null;
    const listener = (res) => {
      console.log(res);
      if (res.accuracy < 100) {
        console.log('定位成功', res);
        finish();
        resolve(res);
      } else {
        finish();
        reject(res);
      }
    };
    const finish = () => {
      console.log('finish');
      uni.offLocationChange(listener);
      uni.stopLocationUpdate();
      clearTimeout(timeout);
      timeout = null;
    };
    uni.startLocationUpdate({
      type: 'gcj02',
      success: (res) => {
        console.log(res);
        if (!timeout) {
          timeout = setTimeout(() => {
            console.log('定位超时');
            finish();
            reject(res);
          }, 6000);
        }
        uni.onLocationChange(listener);
      },
      fail: (err) => {
        console.log(err);
        finish();
        reject(err);
      },
    });
  });
};
